********************************************************************************
*********						 FIG 3	-I-10 W EXPRESSLANES TRIP      *********
*********								DENSITY DURING AM PEAK         *********
********************************************************************************



*******************************************************************************
****						PANEL A										*******
*******************************************************************************
 
 
use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear

drop hour min time 
gen hour=hh(exit_time)
gen min=mm(exit_time)
gen sec=ss(exit_time)

drop if weekend==1
keep if inlist(hour,5,6,7,8,9)
drop if holiday==1

drop if ELspeed==.

keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
drop if charged_toll==0
keep if exit_plaza=="WT06"

gen time=hour+min/60+sec/(60*60)

kdensity time , kernel(epa) gen(t1 epa) bw(.05) nograph n(100)

graph twoway (line epa t1 if t1<=9, lcolor(black) lpattern(solid) ytitle(Smoothed Density) /// 
	xtitle("Hour of Morning Peak") ///
	xline(7, lcolor(gs5) lpattern(shortdash)) ///
	xline(8, lcolor(gs5) lpattern(shortdash)) ///
	xline(8.5, lcolor(gs10) lpattern(shortdash)) ///
	scheme(s1mono) plotregion(style(none))) ///
	,  /// title("SOV Demand Bunching on Exit Time, Plaza 6") ///
	xlabel(5 "5 a.m." 6 "6 a.m." 7 "7 a.m." 8 "8 a.m." 9 "9 a.m." , labsize(small) angle(45)) ///
	xtick(5 6 7 8 9) xmtick(5.5 6.5 7.5 8.5 ) ///
	 name(panela, replace)
 
graph export .\results\maintablesfigs\figs\fig3pa.png, replace  
 

*******************************************************************************
****						PANEL B										*******
******************************************************************************* 

use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear


*WTP calculation
gen TT_dif_hr=dist/MLspeed-dist/ELspeed
gen WTP2=charged_toll/TT_dif_hr
drop if ELspeed==.
drop if TT_dif_hr==.
drop if holiday==1
la var TT_dif_hr "Time in Hours"
drop if dow==0|dow==6
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
keep if hour>4 & hour<9
g exittime=hh(exit_time)+mm(exit_time)/60+ss(exit_time)/(60*60)
g entrytime=hh(entry_time)+mm(entry_time)/60+ss(entry_time)/(60*60)

egen exittimemean=mean(exittime), by(acct_no)
egen exittimesd=sd(exittime), by(acct_no)
egen entrytimemean=mean(entrytime), by(acct_no)
egen entrytimesd=sd(entrytime), by(acct_no)


egen num=seq(), by(acct_no)
egen freq=max(num),by(acct_no)
g exittimediff=exittime-exittimemean
preserve
keep if freq>10


local win1=15/60
local win2=15/60
local win3=0/60
g exit7=exittimemean>7-`win1' & exittimemean<7
g exit730=exittimemean>7.5-`win1' & exittimemean<7.5
g exit8=exittimemean>8-`win1' & exittimemean<8
g exit830=exittimemean>8.5-`win1' & exittimemean<8.5


g entry7=entrytimemean>7-`win1' & entrytimemean<7
g entry730=entrytimemean>7.5-`win1' & entrytimemean<7.5
g entry8=entrytimemean>8-`win1' & entrytimemean<8
g entry830=entrytimemean>8.5-`win1' & entrytimemean<8.5

qui sum exittime if exit7==1
local line=`r(mean)'
twoway kdensity exittime if exit7==1, xtitle("Exit Time for All AM Peak Trips") ///
	title("") text( 1.5 5.75 "6:45-7:00AM", size(medium)) note("") ///
	name(etdist_7, replace) xline(`line') xmtick(5(.25)9) ///
	xlabel(5 "5 a.m." 6 "6 a.m." 7 "7 a.m." 8 "8 a.m." 9 "9 a.m.", labsize(small) angle(45)) ///
	plotregion(lstyle(none)) ylabel(,format(%02.1f)) ytitle("Smoothed Density")
qui sum exittime if exit8==1
local line=`r(mean)'
kdensity exittime if exit8==1,  xtitle("Exit Time for All AM Peak Trips") ///
	title("") text( 1.5 5.75 "7:45-8:00AM", size(medium)) note("") ///
	name(etdist_8, replace) xline(`line') xmtick(5(.25)9) ///
	xlabel(5 "5 a.m." 6 "6 a.m." 7 "7 a.m." 8 "8 a.m." 9 "9 a.m.", labsize(small) angle(45)) ///
	plotregion(lstyle(none)) ylabel(,format(%02.1f)) ytitle("Smoothed Density")


*******************************************************************************
**					Afternoons								*******
*******************************************************************************

use ".\data\clean\I10W_laneuse_dataset_15nov14_wcensus", clear


*WTP calculation
gen TT_dif_hr=dist/MLspeed-dist/ELspeed
gen WTP2=charged_toll/TT_dif_hr
drop if ELspeed==.
drop if TT_dif_hr==.
drop if holiday==1
la var TT_dif_hr "Time in Hours"
keep if acct_type=="PRIVATE"&occupancy~="HOV-3"
g exittime=hh(exit_time)+mm(exit_time)/60+ss(exit_time)/(60*60)
g entrytime=hh(entry_time)+mm(entry_time)/60+ss(entry_time)/(60*60)

egen exittimemean=mean(exittime), by(acct_no)
egen exittimesd=sd(exittime), by(acct_no)
egen entrytimemean=mean(entrytime), by(acct_no)
egen entrytimesd=sd(entrytime), by(acct_no)


egen num=seq(), by(acct_no)
egen freq=max(num),by(acct_no)
g exittimediff=exittime-exittimemean


local win1=15/60
local win2=15/60
local win3=0/60

keep if freq>10
drop if dow==0 | dow==6
keep if hour>14 & hour<19

local win1=15/60
local win2=15/60
local win3=0/60
g exit4=exittimemean>16.3-`win1' & exittimemean<16.3
g exit5=exittimemean>16.8-`win1' & exittimemean<16.8

qui sum exittime if exit4==1
local line=`r(mean)'
twoway kdensity exittime if exit4==1, xtitle("Exit Time for All PM Peak Trips") ///
	title("") text( 1.5 15.75 "4:03-4:18PM", size(medium)) note("") ///
	name(etdist_4, replace) xline(`line')  ylabel(0(.5)1.5) ///
		xmtick(15(.25)19) ///
		xlabel(15 "3 p.m." 16 "4 p.m." 17 "5 p.m." 18 "6 p.m." 19 "7 p.m.", labsize(small) angle(45)) ///
	plotregion(lstyle(none)) ylabel(,format(%02.1f)) ytitle("Smoothed Density") 

qui sum exittime if exit5==1
local line=`r(mean)'
twoway kdensity exittime if exit5==1, xtitle("Exit Time for All PM Peak Trips") ///
	title("") text( 1.5 15.75 "4:33-4:48PM", size(medium)) note("") ///
	name(etdist_5, replace) xline(`line')  ylabel(0(.5)1.5) ///
	xmtick(15(.25)19) ///
	xlabel(15 "3 p.m." 16 "4 p.m." 17 "5 p.m." 18 "6 p.m." 19 "7 p.m.", labsize(small) angle(45)) ///
	plotregion(lstyle(none)) ylabel(,format(%02.1f)) ytitle("Smoothed Density") 

graph combine etdist_7 etdist_8  etdist_4 etdist_5, rows(2)
graph export .\results\maintablesfigs\figs\fig3pb.png, replace
putexcel set ".\results\maintablesfigs\maintextFigsTabs.xlsx", sheet("Figure 2") modify
putexcel A1 = picture(.\results\maintablesfigs\figs\fig3pa.png) 
putexcel A21 = picture(.\results\maintablesfigs\figs\fig3pb.png) 
graph close
